package com.example.springbootsfzy.service.sunnan;

import com.example.springbootsfzy.domain.QaReplies;
import com.example.springbootsfzy.mapper.QaRepliesMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QaRepliesService {
    @Autowired
    private QaRepliesMapper qaRepliesMapper;

    /**
     * 分页查询答疑回复
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     */
    public PageInfo<QaReplies> getQaReplies(int pageNum, int pageSize) {
        // 使用 PageHelper.startPage 设置分页
        PageHelper.startPage(pageNum, pageSize);
        Page<QaReplies> qaReplies = qaRepliesMapper.getQaReplies();
        return new PageInfo<>(qaReplies);
    }
    /**
     * 根据问题id查询答疑回复
     */
    public PageInfo<QaReplies> getQaRepliesById(int pageNum, int pageSize, int id) {
        PageHelper.startPage(pageNum, pageSize);
        Page<QaReplies> qaReplies = qaRepliesMapper.getQaRepliesByQuestionId(id);
        return new PageInfo<>(qaReplies);
    }

    /**
     * 根据会员id查找回答
     */
    public PageInfo<QaReplies> getRepliesByMemberId(int pageNum, int pageSize, int id) {
        PageHelper.startPage(pageNum, pageSize);
        Page<QaReplies> qaReplies = qaRepliesMapper.getRepliesByMemberId(id);
        return new PageInfo<>(qaReplies);
    }

    /**
     * 添加答疑回复
     */
    public int addQaReplies(QaReplies qaReplies) {
        return qaRepliesMapper.insertSelective(qaReplies);
    }

    /**
     * 删除答疑回复
     */
    public int deleteQaReplies(int id) {
        return qaRepliesMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改答疑回复
     */
    public int updateQaReplies(QaReplies qaReplies) {
        return qaRepliesMapper.updateByPrimaryKeySelective(qaReplies);
    }

}
